package dhbw.GUI.Menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;

import javax.swing.*;

import dhbw.Data.Language;
import dhbw.Data.Settings;
import dhbw.GUI.Window.WindowChangePassword;
import dhbw.GUI.Window.WindowInfo;
import dhbw.GUI.Window.WindowNewUser;
import dhbw.GUI.Window.WindowNewVorlesung;
import dhbw.GUI.Window.WindowPersonalien;
import Main.MyController;

public class MenuStudiengangsleiter extends JMenu implements ActionListener{

	private JMenuItem newUserItem, newVorlesungItem, importItem;
	private JMenuItem changePasswordItem,ownDataItem;
	private MyController myc;
	
	public MenuStudiengangsleiter(MyController myc)
	{
		this.myc = myc;
		buildMenu();
	}

	/**
	 * Build JMenu Studiengangsleiter
	 */
	private void buildMenu()
	{
		this.setText(Language.CURSELEADER[myc.getLanguage()]);
		changePasswordItem = new JMenuItem(Language.CHANGEPASSWORD[myc.getLanguage()]);
		changePasswordItem.addActionListener(this);
		ownDataItem = new JMenuItem(Language.PERSONALDATA[myc.getLanguage()]);
		ownDataItem.addActionListener(this);
		ownDataItem.setIcon(Settings.PERSONAL_DATA_ICON);
		changePasswordItem.setIcon(Settings.CHANGEPW_ICON);
		this.add(changePasswordItem);
		this.add(ownDataItem);
		newUserItem = new JMenuItem(Language.ADDNEWUSER[myc.getLanguage()]);
		newUserItem.addActionListener(this);
		newUserItem.setIcon(Settings.NEWUSER_ICON);
		this.add(newUserItem);
		newVorlesungItem = new JMenuItem(Language.ADDNEWVORLESUNG[myc.getLanguage()]);
		newVorlesungItem.addActionListener(this);
		newVorlesungItem.setIcon(Settings.NEWVORLESUNG_ICON);
		this.add(newVorlesungItem);
		importItem = new JMenuItem(Language.DOIMPORT[myc.getLanguage()]);
		importItem.addActionListener(this);
		importItem.setIcon(Settings.IMPORT_ICON);
		this.add(importItem);
	}
	
	@Override
	/**
	 * Click-Listener for JMenu
	 */
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getSource().equals(newUserItem))
		{
			new WindowNewUser(this.myc);
		}
		if(arg0.getSource().equals(newVorlesungItem))
		{
			new WindowNewVorlesung(this.myc);
		}
		if(arg0.getSource().equals(importItem))
		{
			Locale local = Locale.getDefault();
			if(this.myc.getLanguage()==0)
			JOptionPane.setDefaultLocale(Locale.GERMAN);
			if(this.myc.getLanguage()==1)
				JOptionPane.setDefaultLocale(Locale.ENGLISH);
			int wait = JOptionPane.showConfirmDialog(null, Language.WANTTORUNIMPORT[this.myc.getLanguage()],"Import",JOptionPane.YES_NO_OPTION);
			JOptionPane.setDefaultLocale(local);
			if(wait==0)
			{
				this.myc.importCSV();	
			}
		}
		if (arg0.getSource().equals(changePasswordItem)) {
			new WindowChangePassword(this.myc);
		}
		if (arg0.getSource().equals(ownDataItem)) {
			new WindowPersonalien(false, myc, this.myc.getActiveUser());
		}
	}
}
